﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BussinessObject;
using Class_Entity;
using System.Data;
using System.Data.SqlClient;

public partial class Category_Update : System.Web.UI.Page
{
    private DataTable TB;
    private DataTable TB2;
    private DataTable TB3;
    private SqlConnection CON;
    private SqlDataAdapter DA;
    private SqlDataAdapter DA2;
    private SqlDataAdapter DA3;
    string connectString = "server=.;database=dbTrain;integrated security=true";
    protected void Page_Load(object sender, EventArgs e)
    {
        TB = new DataTable();
        TB2 = new DataTable();
        TB3 = new DataTable();
        CON = new SqlConnection(connectString);

        SqlDataAdapter DA3 = new SqlDataAdapter("select TrainName, CategoryID, Train.Seat, TrainTypeID from Train where Train.TrainID = " + Session["ID"].ToString(), CON);
        DA3.Fill(TB3);

        txtName.Text = TB3.Rows[0][0].ToString();
        DropDownListCategory.Text = TB3.Rows[0][1].ToString();
        txtSeat.Text = TB3.Rows[0][2].ToString();
        DropDownListTrainTypeID.Text = TB3.Rows[0][3].ToString();

        if (!IsPostBack)
        {
            SqlDataAdapter DA = new SqlDataAdapter("select * from Category", CON);
            DA.Fill(TB);

            DropDownListCategory.DataSource = TB;
            DropDownListCategory.DataTextField = "CategoryID";
            DropDownListCategory.DataValueField = "CategoryID";
            DropDownListCategory.DataBind();
            

            SqlDataAdapter DA2 = new SqlDataAdapter("select * from TrainType", CON);
            DA2.Fill(TB2);

            DropDownListTrainTypeID.DataSource = TB2;
            DropDownListTrainTypeID.DataTextField = "TrainTypeID";
            DropDownListTrainTypeID.DataValueField = "TrainTypeID";
            DropDownListTrainTypeID.DataBind();
            
        }


    }
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        BO_Train botr = new BO_Train();
        CE__Train cetr = new CE__Train();

        cetr._TrainName = txtName.Text;
        cetr._CategoryID = Convert.ToInt32(DropDownListCategory.Text);
        cetr._Seat = Convert.ToInt32(txtSeat.Text);
        cetr._TrainTypeID = Convert.ToInt32(DropDownListTrainTypeID.Text);

        cetr._TrainID = Convert.ToInt32(Session["ID"].ToString());
        botr.Update_Train(cetr);
        HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + "Done" + "');window.location.href='Train Managerment.aspx';</script>");
    }
}